﻿namespace Numbrella.Client.Common
{
	using System;
	using System.Globalization;
	using System.Windows.Controls;

	public class PortNumberValidationRule : ValidationRule
	{
		public override ValidationResult Validate(object value, CultureInfo cultureInfo)
		{
			int intValue;
			bool isInt = Int32.TryParse(value as string, out intValue);
			if (!isInt || intValue < 0 || intValue > 65535)
				return new ValidationResult(false, "Valid port number should be in 0..65535 range.");
			return ValidationResult.ValidResult;
		}
	}
}